//
//  StoresReponse.m
//  NPS
//
//  Created by jadd on 15/10/20.
//  Copyright © 2015年 jadd. All rights reserved.
//

#import "StoresReponse.h"

@implementation StoresReponse
- (void)setResponseObject:(id)responseObject {
    _responseObject = responseObject;
    if (responseObject) {
        NSString *status = [responseObject objectForKey:@"status"];
      
        if([status isEqualToString:@"success"])
        {
            [MyGlobal sharedVariables].storesArray = [[NSMutableArray alloc] init];
          
            [MyGlobal sharedVariables].token = [responseObject objectForKey:@"u_token"];
            [MyGlobal sharedVariables].random = [responseObject objectForKey:@"random_str"];
            
            NSMutableArray *array = (NSMutableArray *)[responseObject objectForKey:@"list"];
            for (int i = 0; i < [array count]; i++) {
                StoreModel *model = [StoreModel new];
                id object = [array objectAtIndex:i];
                model.storeId = [object objectForKey:@"id"];
                model.name = [object objectForKey:@"name"];
                model.surveyLink = [object objectForKey:@"survey_link"];
                //分享
                model.reportLink = [object objectForKey:@"report_url"];
                //访问
                model.report_auth = [object objectForKey:@"report_auth"];
                //NSLog(@"%@",model.surveyLink);
                model.qr_codeLink = [object objectForKey:@"qr_code"];
                //2015-11-02
               

                model.rspd = [[[NSNumberFormatter alloc] init] stringFromNumber:[object objectForKey:@"rspd"]];
                
                if([object objectForKey:@"sat"])
                {
                    NSNumber *sat = [[object objectForKey:@"sat"] objectForKey:@"count"];
                    model.sat = [NSString stringWithFormat:@"%@",sat];
                    
                    model.satTrend = [[[object objectForKey:@"sat"] objectForKey:@"trend"] intValue];
                    //NSLog(@"%lu",(unsigned long)model.satTrend);
                }
                if([object objectForKey:@"nps"])
                {
                    NSNumber *nps = [[object objectForKey:@"nps"] objectForKey:@"count"];
                    model.recommend = [NSString stringWithFormat:@"%@",nps];
                    //[[[NSNumberFormatter alloc] init] stringFromNumber: nps];
                    
                    model.recommendTrend = [[[object objectForKey:@"nps"] objectForKey:@"trend"] intValue];
                }
                [[MyGlobal sharedVariables].storesArray addObject:model];
            }

        }
        
        while (![[NSUserDefaults standardUserDefaults] synchronize])
        {
        }
    }
}
@end
